package org.gpp.proj1.bone;

import java.io.FileNotFoundException;

import junit.framework.TestCase;

/**
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class BoneFileParserTest extends TestCase {

	/*
	 * Test method for 'org.gpp.proj1.bone.BoneFileParser.loadKeyframes(String, Bone)'
	 */
	public void testLoadKeyframes() throws FileNotFoundException, InvalidKeyframeFileException {
		// Cannot load from keyframe file with null name
		try {
			BoneFileParser.loadKeyframes( null, new Bone( "Bone" ) );
			fail();
		} catch (AssertionError e) {
			// expected error
		}
		
		// Cannot load to null bone
		try {
			BoneFileParser.loadKeyframes( "keyframefile.txt", null );
			fail();
		} catch (AssertionError e) {
			// expected error
		}
		
		// Must throw exception if file isn't found
		try {
			BoneFileParser.loadKeyframes( "keyframefile.txt", new Bone( "Bone" ) );
			fail();
		} catch (FileNotFoundException e) {
			// expected error
		}
		
		// Invalid file
		try {
			BoneFileParser.loadKeyframes( "test/bone/test_keyframes_invalid.txt", new Bone( "bone1" ) );
			fail();
		} catch (InvalidKeyframeFileException e) {
			// expected error
		}
		
		//	Invalid file
		try {
			BoneFileParser.loadKeyframes( "test/bone/test_keyframes_invalid_2.txt", new Bone( "bone1" ) );
			fail();
		} catch (InvalidKeyframeFileException e) {
			// expected error
		}
		
		// Valid file
		Bone bone1 = new Bone( "bone1" );
		
		BoneFileParser.loadKeyframes( "test/bone/test_keyframes.txt", bone1 );
		
		assertEquals( 3, bone1.keyframeAngles.size() );
		assertEquals( 3, bone1.keyframeBoneWidths.size() );
		assertEquals( 3, bone1.keyframeLengths.size() );
		assertEquals( 2, bone1.animations.keySet().size() );
		assertTrue( bone1.animations.get( "anim1" ).loops() );
		assertTrue( bone1.animations.containsKey( "anim1" ) );
		assertTrue( bone1.animations.containsKey( "anim2" ) );
	}

}
